create function [dbo].[SAPTransType2TblName](@TransType nvarchar(100),@BaseRef nvarchar(100))
RETURNS nvarchar(100)
as
begin
declare @A nvarchar(100)
SELECT  @A= 
CASE WHEN @TransType = '-2' THEN 'OJDT'
WHEN @TransType = '13' THEN 'OINV' --AR INVOICE
WHEN @TransType = '14' THEN 'ORCN' -- AR Credit
WHEN @TransType = '15' THEN 'ODLN' --DELIVERY
WHEN @TransType = '16' THEN 'ORDN' --RETURN
WHEN @TransType = '18' THEN 'OPCH' --AP Invoice
WHEN @TransType = '19' THEN 'ORPC' --AP Credit
WHEN @TransType = '20' THEN 'OPDN' --GOods Receipt PO
WHEN @TransType = '21' THEN 'ORPD' --Goods Return
WHEN @TransType = '202' THEN 'PW' 
WHEN @TransType = '21' THEN 'PR' 
WHEN @TransType = '24' THEN 'ORCT' --Incoming Payment
WHEN @TransType = '30' THEN 'OJDT'  --Journal Entry
WHEN @TransType = '46' THEN 'OVPM' --Outgoing Payment
WHEN @TransType = '58' THEN 'ST'  
WHEN @TransType = '59' THEN 'OIGN'	--Goods receipt
WHEN @TransType = '60' THEN 'OIGE' --Goods Issue 
WHEN @TransType = '67' THEN 'OMRV' --inventory revaluation
WHEN @TransType = '69' THEN 'IF' 
WHEN @TransType = '162' THEN 'MR'
ELSE 'XX' END

return 'http://$b1$/link?table='+@A+'&key=' + @BaseRef
end
GO


